"""
_*_ : utf-8 _*_ 
@Time: 2023/11/11 19:45
@Author: LWK
@File: 073_jsonpath
@Project: demo01
"""
import urllib.request

import jsonpath
import json

obj = json.load(open('../temp/kfc_1.json', 'r', encoding='utf-8'))
# kfc所有店名
store_name_list = jsonpath.jsonpath(obj, '$.Table1[*].storeName')

print(store_name_list)

url = 'https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1699753881993_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'
headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76',
    'Referer': 'https://dianying.taobao.com/?spm=a1z21.3046609.city.1.32c0112aurZXxu&city=110100'
}
req = urllib.request.Request(url=url, headers=headers)
res = urllib.request.urlopen(req)
city = res.read().decode('utf-8').split('(')[1].split(')')[0]
# with open('../temp/淘票票城市.json', 'w', encoding='utf8') as fp:
#     fp.write(city)
city_name_list = jsonpath.jsonpath(json.loads(city), '$..regionName')
print(city_name_list)
